public class Test47 {
    public static int add(int x,int y){
        int sum;
        int carry;
        do {
            sum  = x ^ y;//不同为1，相同为0
            carry = (x & y) << 1;//进位的产生等同于，x和y做与运算之后，两个1生成了1，然后向左移位
            x = sum;
            y = carry;
        }while (y != 0); //直到不产生进位为止
        return x;
    }

    public static void main(String[] args) {
        System.out.println(add(1, 2) + ", " + (1 + 2));
        System.out.println(add(13, 34)+ ", " + (13 + 34));
        System.out.println(add(19, 85)+ ", " + (19 + 95));
        System.out.println(add(865, 245)+ ", " + (865 + 245));
    }
}
